package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArSupermarketCategory;
import net.sk.china.city.service.IArSupermarketCategoryService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 商品分类Controller
 * 
 * @author gxf
 * @date 2024-04-25
 */
@Api(tags = "慈善超市商品类别")
@RequiredArgsConstructor
@RestController
@RequestMapping("/supermarket/category")
public class ArSupermarketCategoryController extends BaseController
{
    @Autowired
    private IArSupermarketCategoryService arSupermarketCategoryService;

    /**
     * 查询商品分类列表
     */
    @ApiOperation("商品分类列表")
    @PreAuthorize("hasAnyAuthority('supermarket:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArSupermarketCategory arSupermarketCategory)
    {
        startPage();
        List<ArSupermarketCategory> list = arSupermarketCategoryService.selectArSupermarketCategoryList(arSupermarketCategory);
        return getDataTable(list);
    }

    /**
     * 导出商品分类列表
     */
    @PreAuthorize("hasAnyAuthority('supermarket:category:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArSupermarketCategory arSupermarketCategory)
    {
        List<ArSupermarketCategory> list = arSupermarketCategoryService.selectArSupermarketCategoryList(arSupermarketCategory);
    }

    /**
     * 获取商品分类详细信息
     */
    @ApiOperation("分类详情")
    @PreAuthorize("hasAnyAuthority('supermarket:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arSupermarketCategoryService.selectArSupermarketCategoryById(id));
    }

    /**
     * 新增商品分类
     */
    @ApiOperation("新增分类")
    @PreAuthorize("hasAnyAuthority('supermarket:category:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArSupermarketCategory arSupermarketCategory)
    {
        return toAjax(arSupermarketCategoryService.insertArSupermarketCategory(arSupermarketCategory));
    }

    /**
     * 修改商品分类
     */
    @ApiOperation("修改分类")
    @PreAuthorize("hasAnyAuthority('supermarket:category:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArSupermarketCategory arSupermarketCategory)
    {
        return toAjax(arSupermarketCategoryService.updateArSupermarketCategory(arSupermarketCategory));
    }

    /**
     * 删除商品分类
     */
    @ApiOperation("删除分类")
    @PreAuthorize("hasAnyAuthority('supermarket:category:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arSupermarketCategoryService.deleteArSupermarketCategoryByIds(ids));
    }

    @ApiOperation("类别名和id")
    @GetMapping("/getNameAndId")
    public AjaxResult getNameAndId()
    {
        return success(arSupermarketCategoryService.getNameAndId());
    }
}
